<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: 凡人
  Date: 2021/11/12
  Time: 8:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <link href="${pageContext.request.contextPath}/static/css/index3.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.js" rel="script"></script>
    <script src="${pageContext.request.contextPath}/static/My97DatePicker/WdatePicker.js"></script>
</head>
<body style="margin: 0 auto">
    <c:if test="${user==null}">
        <a href="./toLogin">登陆</a>
    </c:if>
    <c:if test="${user!=null}">
        欢迎用户${user.userName}登陆
    </c:if>
    <form action="./list" method="post">
        <input type="hidden" name="cur" id="cur">
        订单号:<input type="text" name="orderId" value="${d.orderId}">
        配送状态:
            <select name="orderStutus">
                <option value="">请选择</option>
                <c:forEach var="i" items="${status}">
                    <option value="${i}" >${i.text}</option>
                </c:forEach>
            </select><br>
        日期:<input type="text" readonly="readonly" name="startDate"
                  value="<fmt:formatDate value="${d.startDate}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate> "
                  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"> -
            <input type="text" readonly="readonly" name="endDate"
                   value="<fmt:formatDate value="${d.endDate}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>"
                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
        金额:<input type="text" name="minPrice" value="${d.minPrice}"> -
            <input type="text" name="maxPrice" value="${d.maxPrice}">
        <input type="submit" value="搜索">
    </form>
    <a href="./toAdd">添加</a>
    <table>
        <tr>
            <td>订单编号</td>
            <td>订单日期</td>
            <td>物品种类</td>
            <td>订单金额</td>
            <td>订单状态</td>
            <td>操作</td>
        </tr>
        <c:forEach var="i" items="${list.list}">
            <tr>
                <td>${i.orderId}</td>
                <td>
                    <fmt:formatDate value="${i.orderTime}" pattern="yyyy-MM-dd"></fmt:formatDate>
                </td>
                <td>${i.goodsType}</td>
                <td>${i.orderPrice}</td>
                <td>
                    <c:if test="${i.orderStutus.val==0}">
                        ${i.orderStutus.text}
                    </c:if>
                    <c:if test="${i.orderStutus.val==1}">
                        ${i.orderStutus.text}
                    </c:if>
                    <c:if test="${i.orderStutus.val==2}">
                        ${i.orderStutus.text}
                    </c:if>
                </td>
                <td>
                    <c:if test="${i.orderStutus.val==2}">
                        <a href="./toDetail?id=${i.orderId}">查看</a>
                    </c:if>
                    <c:if test="${i.orderStutus.val==0 || i.orderStutus.val==1}">
                        <a href="./toDetail?id=${i.orderId}">查看</a>
                        <a href="./toUpdate?id=${i.orderId}">修改</a>
                        <a href="javascript:void (0)" onclick="toDelete(${i.orderId})">删除</a>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="100" class="align-items-center" style="margin: 0 auto">
                <jsp:include page="/static/common/pages.jsp"></jsp:include>
            </td>
        </tr>
    </table>
</body>
<script>
    function goPage(cur){
        $("#cur").val(cur);
        $("form").submit();
    }
    function toDelete(id){
        if(confirm("确定删除单号为:"+id+"的订单吗?")){
            $.post("./toDelete",{id:id},function(msg){
                if(msg=="ok"){
                    location.reload();
                }
            })
        }
    }
</script>
</html>
